package com.example.java.base.concurrency.threadpool;

import com.example.java.base.concurrency.threadpool.task.SubThread;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * FixedThreadPoolOOM:演示newFixedThreadPool出错的情况
 *
 * @author zhangxiaoxiang
 * @date 2020/11/5
 */
@Slf4j
public class A5FixedThreadPoolOOM {

    private static ExecutorService executorService = Executors.newFixedThreadPool(1);

    public static void main(String[] args) {
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            executorService.execute(new SubThread());
            //Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
            log.info("Integer.MAX_VALUE={} 执行中(演示的时候修改idea(不同版本修改方式可能有点小区别)启动参数合理一点 -Xms10m -Xmx10m )",i);
        }
    }

}

